﻿using System;
using System.Configuration;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;

namespace mojoPortal.Web.RS.PRM.AppCode.Lib
{
    public class RSPRMCommonFunctions : mojoPortal.Web.RS.AppCode.Lib.RSCommonFunctions
    {

        public static string GetPropertyOwnerNameByID(int companyid, int ownerid)
        {
            string ownername = string.Empty;
            String strSQL = "select firstname + ' ' + lastname as ownername from rs_tblowner where ownerid=@ownerid and companyid=@companyid";
            SqlCommand myCommand;
            SqlParameter param;
            SqlConnection myConnection;
            myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings[GetRSCompanyConnectionString()].ToString());
            myCommand = new SqlCommand(strSQL, myConnection);
            SqlDataReader myDataReader;

            param = new SqlParameter();
            param.SqlDbType = SqlDbType.Int;
            param.ParameterName = "@companyid";
            param.Value = companyid;
            myCommand.Parameters.Add(param);

            param = new SqlParameter();
            param.SqlDbType = SqlDbType.Int;
            param.ParameterName = "@ownerid";
            param.Value = ownerid;
            myCommand.Parameters.Add(param);

            myConnection.Open();
            myDataReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);

            if (myDataReader.HasRows)
            {
                myDataReader.Read();
                ownername = myDataReader["ownername"].ToString();
            }
            myConnection.Close();
            return ownername;
        }

        public static string GetPropertyHeadTenantNameByID(int companyid, int tenantid)
        {
            string tenantname = string.Empty;
            String strSQL = "select firstname + ' ' + lastname as tenantname from rs_tblTenant where tenantid=@tenantid and companyid=@companyid";
            SqlCommand myCommand;
            SqlParameter param;
            SqlConnection myConnection;
            myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings[GetRSCompanyConnectionString()].ToString());
            myCommand = new SqlCommand(strSQL, myConnection);
            SqlDataReader myDataReader;

            param = new SqlParameter();
            param.SqlDbType = SqlDbType.Int;
            param.ParameterName = "@companyid";
            param.Value = companyid;
            myCommand.Parameters.Add(param);

            param = new SqlParameter();
            param.SqlDbType = SqlDbType.Int;
            param.ParameterName = "@tenantid";
            param.Value = tenantid;
            myCommand.Parameters.Add(param);

            myConnection.Open();
            myDataReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);

            if (myDataReader.HasRows)
            {
                myDataReader.Read();
                tenantname = myDataReader["tenantname"].ToString();
            }
            myConnection.Close();
            return tenantname;
        }
        public static string GetLeaseStatusNameByID(int companyid, int leaseid)
        {
            string statusname = string.Empty;
            String strSQL = "select statusname from rs_tblstatus where statusid=@leaseid and companyid=@companyid and category='LEASE_CAT'";
            SqlCommand myCommand;
            SqlParameter param;
            SqlConnection myConnection;
            myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings[GetRSCompanyConnectionString()].ToString());
            myCommand = new SqlCommand(strSQL, myConnection);
            SqlDataReader myDataReader;

            param = new SqlParameter();
            param.SqlDbType = SqlDbType.Int;
            param.ParameterName = "@companyid";
            param.Value = companyid;
            myCommand.Parameters.Add(param);

            param = new SqlParameter();
            param.SqlDbType = SqlDbType.Int;
            param.ParameterName = "@leaseid";
            param.Value = leaseid;
            myCommand.Parameters.Add(param);

            myConnection.Open();
            myDataReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);

            if (myDataReader.HasRows)
            {
                myDataReader.Read();
                statusname = myDataReader["statusname"].ToString();
            }
            myConnection.Close();
            return statusname;
        }
    }

}